Other Protocols

MGLCluster

@protocol MGLCluster <MGLFeature>

A protocol that feature subclasses (i.e. those already conforming to the MGLFeature protocol) conform to if they represent clusters.

Currently the only class that conforms to MGLCluster is MGLPointFeatureCluster (a subclass of MGLPointFeature).

To check if a feature is a cluster, check conformity to MGLCluster, for example:

let shape = try! MGLShape(data: clusterShapeData, encoding: String.Encoding.utf8.rawValue)
          
          guard let pointFeature = shape as? MGLPointFeature else {
              throw ExampleError.unexpectedFeatureType
          }
          
          // Check for cluster conformance
          guard let cluster = pointFeature as? MGLCluster else {
              throw ExampleError.featureIsNotACluster
          }
          
          // Currently the only supported class that conforms to `MGLCluster` is
          // `MGLPointFeatureCluster`
          guard cluster is MGLPointFeatureCluster else {
              throw ExampleError.unexpectedFeatureType
          }
          
  • clusterIdentifier

    The identifier for the cluster.

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSUInteger clusterIdentifier;

    Swift

    var clusterIdentifier: UInt { get }
  • clusterPointCount

    The number of points within this cluster

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSUInteger clusterPointCount;

    Swift

    var clusterPointCount: UInt { get }

MGLComputedShapeSourceDataSource

@protocol MGLComputedShapeSourceDataSource <NSObject>

Data source for MGLComputedShapeSource. This protocol defines two optional methods for fetching data, one based on tile coordinates, and one based on a bounding box. Classes that implement this protocol must implement one, and only one of the methods. Methods on this protocol will not be called on main thread, they will be called on the caller’s requestQueue.

  • -featuresInTileAtX:y:zoomLevel:

    Fetch features for a tile. This method will not be invoked on the main queue, it will be invoked on the caller’s requestQueue.

    Declaration

    Objective-C

    - (nonnull NSArray<MGLShape<MGLFeature> *> *)featuresInTileAtX:(NSUInteger)x
                                                                           y:(NSUInteger)y
                                                                   zoomLevel:
                                                                       (NSUInteger)zoomLevel;

    Parameters

    x

    Tile X coordinate.

    y

    Tile Y coordinate.

    zoomLevel

    Tile zoom level.

  • -featuresInCoordinateBounds:zoomLevel:

    Fetch features for a tile. This method will not be invoked on the main queue, it will be invoked on the caller’s requestQueue.

    Declaration

    Objective-C

    - (nonnull NSArray<MGLShape<MGLFeature> *> *)
                  featuresInCoordinateBounds:(MGLCoordinateBounds)bounds
                                   zoomLevel:(NSUInteger)zoomLevel;

    Parameters

    bounds

    The bounds to fetch data for.

    zoomLevel

    Tile zoom level.

MGLMapSnapshotterDelegate

@protocol MGLMapSnapshotterDelegate <NSObject>

Optional methods about significant events when creating a snapshot using an MGLMapSnapshotter object.

  • -mapSnapshotterDidFail:withError:

    Tells the delegate that the snapshotter was unable to load data needed for snapshotting the map.

    This method may be called for a variety of reasons, including a network connection failure or a failure to fetch the style from the server. You can use the given error message to notify the user that map data is unavailable.

    Declaration

    Objective-C

    - (void)mapSnapshotterDidFail:(nonnull MGLMapSnapshotter *)snapshotter
                                  withError:(nonnull NSError *)error;

    Swift

    optional func mapSnapshotterDidFail(_ snapshotter: MGLMapSnapshotter, withError error: Error)

    Parameters

    snapshotter

    The snapshotter that is unable to load the data.

    error

    The reason the data could not be loaded.

  • -mapSnapshotter:didFinishLoadingStyle:

    Tells the delegate that the snapshotter has just finished loading a style.

    This method is called in response to -[MGLMapSnapshotter startWithQueue:completionHandler:] as long as the MGLMapSnapshotter.delegate property is set. Changes to sources or layers of the style being snapshotted do not cause this method to be called.

    Declaration

    Objective-C

    - (void)mapSnapshotter:(nonnull MGLMapSnapshotter *)snapshotter
                  didFinishLoadingStyle:(nonnull MGLStyle *)style;

    Swift

    optional func mapSnapshotter(_ snapshotter: MGLMapSnapshotter, didFinishLoading style: MGLStyle)

    Parameters

    snapshotter

    The snapshotter that has just loaded a style.

    style

    The style that was loaded.

MGLOfflineStorageDelegate

@protocol MGLOfflineStorageDelegate <NSObject>

The MGLOfflineStorageDelegate protocol defines methods that a delegate of an MGLOfflineStorage object can optionally implement to transform various types of URLs before downloading them via the internet.

  • -offlineStorage:URLForResourceOfKind:withURL:

    Sent whenever a URL needs to be transformed.

    Declaration

    Objective-C

    - (nonnull NSURL *)offlineStorage:(nonnull MGLOfflineStorage *)storage
                           URLForResourceOfKind:(MGLResourceKind)kind
                                        withURL:(nonnull NSURL *)url;

    Swift

    func offlineStorage(_ storage: MGLOfflineStorage, urlForResourceOf kind: MGLResourceKind, with url: URL) -> URL

    Parameters

    storage

    The storage object processing the download.

    kind

    The kind of URL to be transformed.

    url

    The original URL to be transformed.

    Return Value

    A URL that will now be downloaded.

MGLStylable

@protocol MGLStylable <NSObject>

An object whose contents are represented by an MGLStyle object that you configure.

  • style

    The style currently displayed in the receiver.

    Note

    The default styles provided by Mapbox contain sources and layers with identifiers that will change over time. Applications that use APIs that manipulate a style’s sources and layers must first set the style URL to an explicitly versioned style using a convenience method like +[MGLStyle outdoorsStyleURLWithVersion:] or a manually constructed NSURL.

    Declaration

    Objective-C

    @property (nonatomic, readonly, nullable) MGLStyle *style;

    Swift

    var style: MGLStyle? { get }